package com.example.chatchatbackend.Controller.sendJob;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.send.SendNotice;
import com.example.chatchatbackend.entity.vo.response.SendNoticeVO;
import com.example.chatchatbackend.service.sendJob.SendNoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */
@Slf4j
@RestController
@RequestMapping("/api/sendNotice")
public class SendNoticeController {

    @Autowired
    private SendNoticeService sendNoticeService;

    @GetMapping
    public RestBean<List<SendNoticeVO>> getAllComment(){
        return RestBean.success(sendNoticeService.getAllSendNotice());
    }

    @PostMapping
    public RestBean<SendNoticeVO> insertSendNotice(@RequestBody SendNoticeVO sendNoticeVO){
        SendNoticeVO insertSendNoticeVO = sendNoticeService.insertSendNotice(sendNoticeVO);
        return RestBean.success(insertSendNoticeVO);

    }

    @PostMapping("/list")
    public RestBean<List<SendNoticeVO>> insertSendNoticeList (@RequestBody List<SendNoticeVO> sendNoticeVO){
        List<SendNoticeVO> SendNoticeList = sendNoticeService.insertSendNoticeList(sendNoticeVO);
        return RestBean.success(SendNoticeList);
    }

    @GetMapping("/pageThree")
    public RestBean<IPage<SendNotice>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                                 @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(sendNoticeService.pageThree(pageNum, pageSize));
    }

    @PutMapping
    public RestBean<SendNoticeVO> updateSendNotice(@RequestBody SendNoticeVO sendNoticeVO){
        return RestBean.success(sendNoticeService.updateSendNotice(sendNoticeVO));

    }

    @DeleteMapping("/ids")
    public RestBean<String> delete(@RequestBody List<Integer> ids) {
        sendNoticeService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }

    @GetMapping("/name")
    public RestBean<List<SendNoticeVO>> findByTitle(@RequestBody String title ){
        List<SendNoticeVO> sendNoticeVOList = sendNoticeService.findByTitle(title);
        return RestBean.success(sendNoticeVOList);
    }

}
